home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Strings / c / regexp < prev   
Encoding:
Text File  |  1996-08-26  |  857 b   |  42 lines

  1. #include <stdio.h>
  2. #define STDC_HEADERS 1
  3. #define HAVE_STRING_H 1
  4. #define HAVE_ALLOCA_H 1
  5. #include "regex.h"
  6. #include "regex.c"
  7.  
  8. void* C_REGEXP_compile( void* string, void* nocase )
  9. {
  10.   int res,flags;
  11.   regex_t *r;
  12. /*  re_syntax_options = RE_SYNTAX_EGREP; */
  13.   r = (regex_t*)malloc(sizeof(regex_t));
  14.   flags = REG_EXTENDED | ( ((int)nocase!=0) ? REG_ICASE : 0 );
  15.   res = regcomp(r,(char*)string,flags);
  16.   if( !res ) return (void*)r;
  17.   free(r);
  18.   return (void*)0;
  19. }
  20.  
  21. void C_REGEXP_match( void* regexpr, void* string, void* beg, void* end)
  22. {
  23.   int res;
  24.   regmatch_t match;
  25.   res = regexec((regex_t*)regexpr,(char*)string,
  26.         1,&match,0);
  27.   if( res ) {
  28.     *(int*)beg = -1;
  29.     *(int*)end = -1;
  30.   } else {
  31.     *(int*)beg = (int)(match.rm_so);
  32.     *(int*)end = (int)(match.rm_eo);
  33.   }
  34. }
  35.  
  36. void C_REGEXP_free( void* regexpr )
  37. {
  38.   regfree( (regex_t*)regexpr );
  39. }
  40.  
  41.  
  42.